#ifndef __M_LOGGER_H__
#define __M_LOGGER_H__
#include <stdio.h>
#include <time.h>

enum LogLevel
{
    LOG_INF = 0,
    LOG_DBG = 1,
    LOG_ERR = 2
};
#define DEFAULT_LOG_LEVEL LOG_INF

#define LOG(level, format, ...)                                              \
    do                                                                       \
    {                                                                        \
        if ((level) < DEFAULT_LOG_LEVEL)                                     \
            break;                                                           \
        time_t t = time(NULL);                                               \
        struct tm *lt = localtime(&t);                                       \
        char buf[32] = {0};                                                  \
        strftime(buf, sizeof(buf), "%H:%M:%S", lt);                          \
        char msgbuf[4096];                                                   \
        snprintf(msgbuf, sizeof(msgbuf), format, ##__VA_ARGS__);             \
        fprintf(stdout, "[%s %s:%d] %s\n", buf, __FILE__, __LINE__, msgbuf); \
    } while (0)

#define ILOG(format, ...) LOG(LOG_INF, format, ##__VA_ARGS__)
#define DLOG(format, ...) LOG(LOG_DBG, format, ##__VA_ARGS__)
#define ELOG(format, ...) LOG(LOG_ERR, format, ##__VA_ARGS__)

#endif
